import { getAction, putAction, postAction } from '@/api/manage'
import { serviceApi } from '@/api/common.js'

/**
 * 公共API接口
 */
export const api = {
  userList: serviceApi.auth + '/users',
  list: serviceApi.auth + '/users/tenants/child-users',
  listUserTenant: (tenantId, userId) => serviceApi.auth + `/tenants/${tenantId}/users/${userId}/list-user-tenant`,
  generateUserId: serviceApi.auth + '/users/generate-userid',
  delete: (userId, tenantId) => serviceApi.auth + `/tenants/${tenantId}/users/${userId}`
}

/**
 * 添加用户
 * @param {*} params
 * @returns
 */
export const addTenantUser = (params) => postAction(serviceApi.auth + '/users/tenants/add-user', params);

/**
* 编辑用户
* @param {*} params
* @returns
*/
export const editTenantUser = (params) => putAction(serviceApi.auth + '/users/tenants/edit-user', params);

/**
 * 重置密码
 * @param {*} params
 * @returns
 */
export const resetPassword = params => putAction(serviceApi.auth + '/users/password-reset', params);

/**
 * 获取租户列表
 * @param {*} params
 * @returns
 */
export const queryTenantChildList = (tenantId, params) => getAction(serviceApi.auth + `/tenants/${tenantId}/children/list`, params);

/**
 * 获取租户角色
 * @param {*} params
 * @returns
 */
export const queryTenantRole = (tenantId, params) => getAction(serviceApi.auth + `/roles/tenants/${tenantId}`, params);

/**
* 获取租户部门
* @param {*} params
* @returns
*/
export const queryDepartByTenantId = (tenantId, params) => getAction(serviceApi.auth + `/departs/tenants/${tenantId}`, params);

/**
* 获取租户用户
* @param {*} params
* @returns
*/
export const getUserByIdAndTenantId = (tenantId, userId, params) => getAction(serviceApi.auth + `/tenants/${tenantId}/users/${userId}/list-user-tenant`, params);

/**
 * 冻结用户
 * @param {*} params
 * @returns
 */
export const frozenBatch = params => putAction(serviceApi.auth + '/users/frozen', params)

/**
* 获取用户列表
* @param params
* @returns {AxiosPromise}
*/
export const getUserList = params => getAction(api.userList, params)

/**
* 通过用户ID获取租户列表
* @param params
* @returns {AxiosPromise}
*/
export const listTenantsByUserId = (userId, params) => getAction(serviceApi.auth + `/users/${userId}/tenants`, params);

/**
 * 切换租户
 * @param {*} params
 * @returns
 */
export const switchTenant = (userId, tenantId, params) => getAction(serviceApi.auth + `/users/${userId}/switch/${tenantId}`, params);

// 引入生成添加用户情况下的url
export const generateUserId = (params) => getAction(api.generateUserId, params);

/**
 * 后期需跟addTenantUser 合并
 * @param {*} tenantId
 * @param {*} params
 * @returns
 */
export const addUserTenant = (tenantId, params) => postAction(serviceApi.auth + `/tenants/${tenantId}/users`, params);

/**
 * 后期需跟editTenantUser 合并
 * @param {*} tenantId
 * @param {*} params
 * @returns
 */
export const editUserTenant = (tenantId, params) => putAction(serviceApi.auth + `/tenants/${tenantId}/users`, params);

/**
 * 重复校验用户租户信息
 * @param params
 * @returns {AxiosPromise}
 */
export const checkUserTenant = (params) => getAction(serviceApi.auth + '/duplicate/check-user-tenant', params);
